package b.b.g;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.PorterDuff.Mode;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import android.view.InflateException;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.SubMenu;
import android.view.View;
import b.b.g.i.i;
import b.b.g.i.j;
import b.b.h.f0;
import b.b.h.o;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* compiled from: SupportMenuInflater */
public class f extends MenuInflater {
    public static final Class<?>[] e;
    public static final Class<?>[] f;
    public final Object[] a;
    public final Object[] b;
    public Context c;
    public Object d;

    /* compiled from: SupportMenuInflater */
    public static class a implements OnMenuItemClickListener {
        public static final Class<?>[] c = new Class[]{MenuItem.class};
        public Object a;
        public Method b;

        public a(Object obj, String str) {
            this.a = obj;
            Class cls = obj.getClass();
            try {
                this.b = cls.getMethod(str, c);
            } catch (Exception e) {
                StringBuilder j = c.b.a.a.a.j("Couldn't resolve menu item onClick handler ", str, " in class ");
                j.append(cls.getName());
                InflateException inflateException = new InflateException(j.toString());
                inflateException.initCause(e);
                throw inflateException;
            }
        }

        public boolean onMenuItemClick(MenuItem menuItem) {
            try {
                if (this.b.getReturnType() == Boolean.TYPE) {
                    return ((Boolean) this.b.invoke(this.a, new Object[]{menuItem})).booleanValue();
                }
                this.b.invoke(this.a, new Object[]{menuItem});
                return true;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    /* compiled from: SupportMenuInflater */
    public class b {
        public b.i.k.b A;
        public CharSequence B;
        public CharSequence C;
        public ColorStateList D = null;
        public Mode E = null;
        public Menu a;
        public int b;
        public int c;
        public int d;
        public int e;
        public boolean f;
        public boolean g;
        public boolean h;
        public int i;
        public int j;
        public CharSequence k;
        public CharSequence l;
        public int m;
        public char n;
        public int o;
        public char p;
        public int q;
        public int r;
        public boolean s;
        public boolean t;
        public boolean u;
        public int v;
        public int w;
        public String x;
        public String y;
        public String z;

        public b(Menu menu) {
            this.a = menu;
            this.b = 0;
            this.c = 0;
            this.d = 0;
            this.e = 0;
            this.f = true;
            this.g = true;
        }

        public SubMenu a() {
            this.h = true;
            SubMenu addSubMenu = this.a.addSubMenu(this.b, this.i, this.j, this.k);
            c(addSubMenu.getItem());
            return addSubMenu;
        }

        public final <T> T b(String str, Class<?>[] clsArr, Object[] objArr) {
            try {
                Constructor constructor = Class.forName(str, false, f.this.c.getClassLoader()).getConstructor(clsArr);
                constructor.setAccessible(true);
                str = constructor.newInstance(objArr);
                return str;
            } catch (Exception e) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Cannot instantiate class: ");
                stringBuilder.append(str);
                Log.w("SupportMenuInflater", stringBuilder.toString(), e);
                return null;
            }
        }

        public final void c(MenuItem menuItem) {
            int i = VERSION.SDK_INT;
            int i2 = 0;
            menuItem.setChecked(this.s).setVisible(this.t).setEnabled(this.u).setCheckable(this.r >= 1).setTitleCondensed(this.l).setIcon(this.m);
            int i3 = this.v;
            if (i3 >= 0) {
                menuItem.setShowAsAction(i3);
            }
            if (this.z != null) {
                if (f.this.c.isRestricted()) {
                    throw new IllegalStateException("The android:onClick attribute cannot be used within a restricted context");
                }
                f fVar = f.this;
                if (fVar.d == null) {
                    fVar.d = fVar.a(fVar.c);
                }
                menuItem.setOnMenuItemClickListener(new a(fVar.d, this.z));
            }
            if (this.r >= 2) {
                if (menuItem instanceof i) {
                    i iVar = (i) menuItem;
                    iVar.x = (iVar.x & -5) | 4;
                } else if (menuItem instanceof j) {
                    j jVar = (j) menuItem;
                    try {
                        if (jVar.e == null) {
                            jVar.e = jVar.d.getClass().getDeclaredMethod("setExclusiveCheckable", new Class[]{Boolean.TYPE});
                        }
                        jVar.e.invoke(jVar.d, new Object[]{Boolean.TRUE});
                    } catch (Exception e) {
                        Log.w("MenuItemWrapper", "Error while calling setExclusiveCheckable", e);
                    }
                }
            }
            String str = this.x;
            if (str != null) {
                menuItem.setActionView((View) b(str, f.e, f.this.a));
                i2 = 1;
            }
            i3 = this.w;
            if (i3 > 0) {
                if (i2 == 0) {
                    menuItem.setActionView(i3);
                } else {
                    Log.w("SupportMenuInflater", "Ignoring attribute 'itemActionViewLayout'. Action view already specified.");
                }
            }
            b.i.k.b bVar = this.A;
            if (bVar != null) {
                if (menuItem instanceof b.i.f.a.b) {
                    ((b.i.f.a.b) menuItem).a(bVar);
                } else {
                    Log.w("MenuItemCompat", "setActionProvider: item does not implement SupportMenuItem; ignoring");
                }
            }
            CharSequence charSequence = this.B;
            boolean z = menuItem instanceof b.i.f.a.b;
            if (z) {
                ((b.i.f.a.b) menuItem).setContentDescription(charSequence);
            } else if (i >= 26) {
                menuItem.setContentDescription(charSequence);
            }
            charSequence = this.C;
            if (z) {
                ((b.i.f.a.b) menuItem).setTooltipText(charSequence);
            } else if (i >= 26) {
                menuItem.setTooltipText(charSequence);
            }
            char c = this.n;
            int i4 = this.o;
            if (z) {
                ((b.i.f.a.b) menuItem).setAlphabeticShortcut(c, i4);
            } else if (i >= 26) {
                menuItem.setAlphabeticShortcut(c, i4);
            }
            c = this.p;
            i4 = this.q;
            if (z) {
                ((b.i.f.a.b) menuItem).setNumericShortcut(c, i4);
            } else if (i >= 26) {
                menuItem.setNumericShortcut(c, i4);
            }
            Mode mode = this.E;
            if (mode != null) {
                if (z) {
                    ((b.i.f.a.b) menuItem).setIconTintMode(mode);
                } else if (i >= 26) {
                    menuItem.setIconTintMode(mode);
                }
            }
            ColorStateList colorStateList = this.D;
            if (colorStateList == null) {
                return;
            }
            if (z) {
                ((b.i.f.a.b) menuItem).setIconTintList(colorStateList);
            } else if (i >= 26) {
                menuItem.setIconTintList(colorStateList);
            }
        }
    }

    static {
        Class[] clsArr = new Class[]{Context.class};
        e = clsArr;
        f = clsArr;
    }

    public f(Context context) {
        super(context);
        this.c = context;
        Object[] objArr = new Object[]{context};
        this.a = objArr;
        this.b = objArr;
    }

    public final Object a(Object obj) {
        if (obj instanceof Activity) {
            return obj;
        }
        if (obj instanceof ContextWrapper) {
            obj = a(((ContextWrapper) obj).getBaseContext());
        }
        return obj;
    }

    public final void b(XmlPullParser xmlPullParser, AttributeSet attributeSet, Menu menu) throws XmlPullParserException, IOException {
        String str;
        String name;
        XmlPullParser xmlPullParser2;
        AttributeSet attributeSet2 = attributeSet;
        b bVar = new b(menu);
        int eventType = xmlPullParser.getEventType();
        while (true) {
            str = "menu";
            if (eventType == 2) {
                name = xmlPullParser.getName();
                if (name.equals(str)) {
                    eventType = xmlPullParser.next();
                } else {
                    throw new RuntimeException(c.b.a.a.a.D("Expecting menu, got ", name));
                }
            }
            eventType = xmlPullParser.next();
            if (eventType == 1) {
                break;
            }
            xmlPullParser2 = xmlPullParser;
        }
        Object obj = null;
        Object obj2 = null;
        Object obj3 = null;
        while (obj == null) {
            if (eventType != 1) {
                String str2 = "item";
                String str3 = "group";
                if (eventType != 2) {
                    if (eventType == 3) {
                        name = xmlPullParser.getName();
                        if (obj2 != null && name.equals(obj3)) {
                            xmlPullParser2 = xmlPullParser;
                            obj3 = null;
                            obj2 = null;
                            eventType = xmlPullParser.next();
                        } else if (name.equals(str3)) {
                            bVar.b = 0;
                            bVar.c = 0;
                            bVar.d = 0;
                            bVar.e = 0;
                            bVar.f = true;
                            bVar.g = true;
                        } else if (name.equals(str2)) {
                            if (!bVar.h) {
                                b.i.k.b bVar2 = bVar.A;
                                if (bVar2 == null || !bVar2.a()) {
                                    bVar.h = true;
                                    bVar.c(bVar.a.add(bVar.b, bVar.i, bVar.j, bVar.k));
                                } else {
                                    bVar.a();
                                }
                            }
                        } else if (name.equals(str)) {
                            xmlPullParser2 = xmlPullParser;
                            obj = 1;
                            eventType = xmlPullParser.next();
                        }
                    }
                } else if (obj2 == null) {
                    name = xmlPullParser.getName();
                    if (name.equals(str3)) {
                        TypedArray obtainStyledAttributes = f.this.c.obtainStyledAttributes(attributeSet2, b.b.b.p);
                        bVar.b = obtainStyledAttributes.getResourceId(1, 0);
                        bVar.c = obtainStyledAttributes.getInt(3, 0);
                        bVar.d = obtainStyledAttributes.getInt(4, 0);
                        bVar.e = obtainStyledAttributes.getInt(5, 0);
                        bVar.f = obtainStyledAttributes.getBoolean(2, true);
                        bVar.g = obtainStyledAttributes.getBoolean(0, true);
                        obtainStyledAttributes.recycle();
                    } else if (name.equals(str2)) {
                        char c;
                        ColorStateList colorStateList;
                        f0 p = f0.p(f.this.c, attributeSet2, b.b.b.q);
                        bVar.i = p.l(2, 0);
                        bVar.j = (p.j(5, bVar.c) & -65536) | (p.j(6, bVar.d) & 65535);
                        bVar.k = p.n(7);
                        bVar.l = p.n(8);
                        bVar.m = p.l(0, 0);
                        str2 = p.m(9);
                        if (str2 == null) {
                            c = 0;
                        } else {
                            c = str2.charAt(0);
                        }
                        bVar.n = c;
                        bVar.o = p.j(16, 4096);
                        str2 = p.m(10);
                        if (str2 == null) {
                            c = 0;
                        } else {
                            c = str2.charAt(0);
                        }
                        bVar.p = c;
                        bVar.q = p.j(20, 4096);
                        if (p.o(11)) {
                            bVar.r = p.a(11, false);
                        } else {
                            bVar.r = bVar.e;
                        }
                        bVar.s = p.a(3, false);
                        bVar.t = p.a(4, bVar.f);
                        bVar.u = p.a(1, bVar.g);
                        bVar.v = p.j(21, -1);
                        bVar.z = p.m(12);
                        bVar.w = p.l(13, 0);
                        bVar.x = p.m(15);
                        str2 = p.m(14);
                        bVar.y = str2;
                        Object obj4 = str2 != null ? 1 : null;
                        if (obj4 != null && bVar.w == 0 && bVar.x == null) {
                            bVar.A = (b.i.k.b) bVar.b(str2, f, f.this.b);
                        } else {
                            if (obj4 != null) {
                                Log.w("SupportMenuInflater", "Ignoring attribute 'actionProviderClass'. Action view already specified.");
                            }
                            bVar.A = null;
                        }
                        bVar.B = p.n(17);
                        bVar.C = p.n(22);
                        if (p.o(19)) {
                            bVar.E = o.c(p.j(19, -1), bVar.E);
                            colorStateList = null;
                        } else {
                            colorStateList = null;
                            bVar.E = null;
                        }
                        if (p.o(18)) {
                            bVar.D = p.c(18);
                        } else {
                            bVar.D = colorStateList;
                        }
                        p.b.recycle();
                        bVar.h = false;
                    } else {
                        if (name.equals(str)) {
                            b(xmlPullParser, attributeSet2, bVar.a());
                        } else {
                            xmlPullParser2 = xmlPullParser;
                            obj2 = 1;
                            obj3 = name;
                        }
                        eventType = xmlPullParser.next();
                    }
                }
                xmlPullParser2 = xmlPullParser;
                eventType = xmlPullParser.next();
            } else {
                throw new RuntimeException("Unexpected end of document");
            }
        }
    }

    public void inflate(int i, Menu menu) {
        String str = "Error inflating menu XML";
        if (menu instanceof b.i.f.a.a) {
            XmlResourceParser xmlResourceParser = null;
            try {
                xmlResourceParser = this.c.getResources().getLayout(i);
                b(xmlResourceParser, Xml.asAttributeSet(xmlResourceParser), menu);
                xmlResourceParser.close();
            } catch (XmlPullParserException e) {
                throw new InflateException(str, e);
            } catch (IOException e2) {
                throw new InflateException(str, e2);
            } catch (Throwable th) {
                if (xmlResourceParser != null) {
                    xmlResourceParser.close();
                }
            }
        } else {
            super.inflate(i, menu);
        }
    }
}
